<?php

namespace App\Http\Requests\Reservation;

use Illuminate\Foundation\Http\FormRequest;

class ScheduleUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     * @return array
     */
    public function rules()
    {
        return [
            'id'                  => 'integer',
            'doctor_id'           => 'required|integer|min:1',
            'time'                => 'required|date',
            'room'                => 'integer|min:1',
            'workload'            => 'array|min:1|max:8',
            'workload.1.*.start'  => 'required_with:workload.1.*|integer|min:8|max:12',
            'workload.1.*.end'    => 'required_with:workload.1.*|integer|min:8|max:12',
            'workload.1.*.number' => 'required_with:workload.1.*|integer|min:1|max:999',
            'workload.0.*.start'  => 'required_with:workload.0.*|integer|min:13|max:18',
            'workload.0.*.end'    => 'required_with:workload.0.*|integer|min:13|max:18',
            'workload.0.*.number' => 'required_with:workload.0.*|integer|min:1|max:999',
        ];
    }

    public function messages()
    {
        return [
            'doctor_id.required' => '医生ID 字段不能为空。',
            'doctor_id.integer'  => '医生ID 必须是一个数字。',
            'doctor_id.min'      => '医生ID 必须大于等于 :min。',
            'time.required'      => '时间 不能为空。',
            'time.integer'       => '时间字段 必须是一个有效的日期。',
            'workload.required'  => '预约时间设置 不能为空。',
        ];
    }
}
